package com.frxuexi.base.http

import com.frxuexi.base.entity.AppsEntity
import com.frxuexi.base.entity.NewsBean
import com.frxuexi.base.entity.NewsBeanItem
import com.frxuexi.base.entity.NoticeBean
import com.frxuexi.base.entity.NoticeBeanItem
import com.frxuexi.base.entity.ParkBean
import com.frxuexi.base.entity.ParkBeanItem
import com.frxuexi.base.entity.PatrolBean
import com.frxuexi.base.entity.RepairBean
import com.frxuexi.base.entity.RepairBeanItem
import com.frxuexi.base.entity.Res
import com.frxuexi.base.entity.SignBean
import com.frxuexi.base.entity.SignBeanItem
import com.frxuexi.base.entity.UserBean
import com.frxuexi.base.entity.VisitBean
import com.frxuexi.base.entity.VisitBeanItem
import kotlinx.coroutines.flow.Flow
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query

interface ApiService {

    @GET("/api/sysapp/all")
    fun getApps():Flow<Res<AppsEntity>>

    @POST("/api/user/register")
    fun register(@Query("username")username:String,@Query("password")password:String):Flow<Res<Any>>

    @POST("/api/user/login")
    fun login(@Query("username")username:String,@Query("password")password:String):Flow<Res<Any>>

    @GET("/api/announcements")
    fun getNotices(@Query("page")page:Int,@Query("size")size:Int):Flow<Res<NoticeBean>>

    //车位
    @GET("/api/parking-spaces/type/{spaceType}")
    fun getParkByType(@Path("spaceType")spaceType:String):Flow<Res<ParkBean>>

    @GET("/api/parking-spaces/status/{spaceStatus}")
    fun getParkByStatus(@Path("spaceStatus")spaceStatus:String):Flow<Res<ParkBean>>

    @GET("/api/parking-spaces/area/{areaId}")
    fun getParkByArea(@Path("areaId")areaId:Int):Flow<Res<ParkBean>>

    @GET("/api/parking-spaces/license/{licensePlate}")
    fun getParkByCarNo(@Path("licensePlate")licensePlate:String):Flow<Res<ParkBeanItem>>

    @GET("/api/parking-spaces/user/{userId}")
    fun getParkByUid(@Path("userId")userId:Int):Flow<Res<ParkBeanItem>>

    @POST("/api/parking-spaces")
    fun addPark(@Body body: RequestBody):Flow<Res<ParkBeanItem>>

    @GET("/api/parking-spaces/{id}")
    fun getParkById(@Path("id")id:Int):Flow<Res<ParkBeanItem>>

    @PUT("/api/parking-spaces/{id}")
    fun updatePark(@Path("id")id:Int,@Body body: RequestBody):Flow<Res<ParkBeanItem>>

    @DELETE("/api/parking-spaces/{id}")
    fun deletePark(@Path("id")id:Int):Flow<Res<Boolean>>

    //维修
    @GET("/api/repair-orders")
    fun getRepairs():Flow<Res<RepairBean>>

    @GET("/api/repair-orders/order-number/{orderNumber}")
    fun getRepairByNum(@Path("orderNumber")orderNumber:String):Flow<Res<RepairBeanItem>>

    @GET("/api/repair-orders/search")
    fun getRepairByName(@Query("repairName")repairName:String):Flow<Res<RepairBean>>

    //上传
    @Multipart
    @POST("/api/file/upload")
    fun upload(@Part part:List<MultipartBody.Part>,@Query("modulename")modulename:String,@Query("userid")userid:String):Flow<Res<String>>

    @POST("/api/repair-orders")
    fun addRepair(@Body body: RequestBody):Flow<Res<RepairBeanItem>>

    @GET("/api/repair-orders/{id}")
    fun getRepairById(@Path("id")id:Int):Flow<Res<RepairBeanItem>>

    @DELETE("/api/repair-orders/{id}")
    fun deleteRepair(@Path("id")id:Int):Flow<Res<Boolean>>

    @PUT("/api/repair-orders/{id}")
    fun updateRepair(@Path("id")id:Int,@Body body: RequestBody):Flow<Res<RepairBeanItem>>

    //预约来访
    @GET("/api/visit-appointments")
    fun getVisits():Flow<Res<VisitBean>>

    @GET("/api/visit-appointments/status/{status}")
    fun getVisitByStatus(@Path("status")status:String):Flow<Res<VisitBean>>

    @DELETE("/api/visit-appointments/{id}")
    fun deleteVisit(@Path("id")id:Int):Flow<Res<Boolean>>

    @GET("/api/visit-appointments/search/name")
    fun getVisitsByName(@Query("name")name:String):Flow<Res<VisitBean>>

    @GET("/api/visit-appointments/search/purpose")
    fun getVisitsByPurpose(@Query("purpose")purpose:String):Flow<Res<VisitBean>>

    @POST("/api/visit-appointments")
    fun addVisit(@Body body: RequestBody):Flow<Res<VisitBeanItem>>

    @GET("/api/visit-appointments/{id}")
    fun getVisitById(@Path("id")id:Int):Flow<Res<VisitBeanItem>>

    @PATCH("/api/visit-appointments/approve/{id}")
    fun approveVisit(@Path("id")id:Int):Flow<Res<VisitBeanItem>>

    @PATCH("/api/visit-appointments/reject/{id}")
    fun rejectVisit(@Path("id")id:Int):Flow<Res<VisitBeanItem>>

    @PUT("/api/visit-appointments/{id}")
    fun updateVisit(@Path("id")id:Int,@Body body: RequestBody):Flow<Res<VisitBeanItem>>

    //公告
    @POST("/api/announcements")
    fun addNotice(@Body body: RequestBody):Flow<Res<NoticeBeanItem>>

    @GET("/api/announcements/getAnnouncementByUserId")
    fun getNoticeByUid(@Query("userId")userId:Int):Flow<Res<NoticeBean>>

    @GET("/api/announcements/{id}")
    fun getNoticeById(@Path("id")id:Int):Flow<Res<NoticeBeanItem>>

    //文化新闻
    @GET("/api/news")
    fun getNews():Flow<Res<NewsBean>>

    @GET("/api/news/search")
    fun getNewsByCon(@Query("keyword")keyword:String):Flow<Res<NewsBean>>

    @DELETE("/api/news/{id}")
    fun deleteNews(@Path("id")id:Int):Flow<Res<Boolean>>

    @POST("/api/news")
    fun addNews(@Body body: RequestBody):Flow<Res<NewsBeanItem>>

    @GET("/api/news/{id}")
    fun getNewsById(@Path("id")id:Int):Flow<Res<NewsBeanItem>>

    @PUT("/api/news/{id}")
    fun updateNews(@Path("id")id:Int,@Body body: RequestBody):Flow<Res<NewsBeanItem>>

    @PATCH("/api/news/revoke/{id}")
    fun revokeNews(@Path("id")id:Int):Flow<Res<Boolean>>

    //打卡
    @POST("/api/attendances")
    fun addSign(@Body body: RequestBody):Flow<Res<SignBeanItem>>

    @GET("/api/attendances/user/{userId}")
    fun getSigns(@Path("userId")userId:Int):Flow<Res<SignBean>>

    @GET("/api/patrol-tasks/by-person/{personId}")
    fun getPatrolByUid(@Path("personId")personId:Int):Flow<Res<PatrolBean>>
}